package String;

import org.junit.Test;

public class StringDemo {
    @Test
    public void test1(){
        //String是引用类型
        String string1 = "abc";
        String string2 = new String("abc");
        String string3 = "abc";
        System.out.println(string1 == string2);//false
        System.out.println(string1 == string3);//true
        System.out.println(string2 == string3);//false

        System.out.println(string1.equals(string2));//true
        System.out.println(string1.equals(string3));//true
        System.out.println(string2.equals(string3));//true
    }
    @Test
    public void test2(){
        String str = "java Android";
        String nest = str.replace('A','B');
        System.out.println(str);
        System.out.println(nest);
        String[] array = str.split("A");
        for(String s:array){
            System.out.print(s);
        }
    }

    @Test
    public void test3(){
        //String长度不能变化
        //StringBuffer,StringBuilder长度能变
        String string = "abc";
        //StringBuffer安全，加密，互斥
        StringBuffer stringBuffer = new StringBuffer("def");
        //StringBuilder
        StringBuilder stringBuilder = new StringBuilder("fhd");

        string+="ak4";//实质是new了一个新的String对象
        stringBuffer.append("ak1").append("ak2");
        stringBuilder.append("ak3");

        System.out.println(string);
        System.out.println(stringBuffer);
        System.out.println(stringBuilder);
        //abcak4
        //defak1ak2
        //fhdak3
    }

    @Test
    public void test4(){
        //数字转字符串
        String str = 12+"";
        String str1 = Integer.toString(12);
        String str2 = Double.toString(3.14);
        //字符串转数字
        String str3 = "3.14";
        Double d = Double.parseDouble(str3);

        //
        String str4 = "java";
        System.out.println(str4.toUpperCase());
    }
}
